package com.ilop.sthome.ui.activity.config;

import android.content.Intent;

import com.example.common.base.BaseBindActivity;
import com.example.common.utils.LiveDataBus;
import com.ilop.sthome.common.CommonId;
import com.ilop.sthome.utils.system.NetWorkUtil;
import com.siterwell.familywellplus.R;
import com.siterwell.familywellplus.databinding.ActivityAddIpcBinding;

/**
 * @author skygge
 * @date 2020-02-18.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：添加摄像头引导页面
 */
public class AddCameraGuideActivity extends BaseBindActivity<ActivityAddIpcBinding> {

    private int ADD_NEW_IPC = 1;
    private int ADD_SHARE_IPC = 2;
    private int ADD_LOCAL_IPC = 3;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_add_ipc;
    }

    @Override
    protected void initDataBus() {
        super.initDataBus();
        LiveDataBus.get().with(CommonId.REFRESH_CAMERA, String.class).observe(this, s -> {
            if (s!=null){
                finish();
            }
        });
    }

    @Override
    protected void initListener() {
        super.initListener();
        mDBind.ivAddCameraBack.setOnClickListener(view -> finish());

        mDBind.addNewIpc.setOnClickListener(view -> startToConfigCamera(ADD_NEW_IPC));

        mDBind.addShareIpc.setOnClickListener(view -> startToConfigCamera(ADD_SHARE_IPC));

        mDBind.addLocalIpc.setOnClickListener(view -> {
            if(NetWorkUtil.getInstance().getNetWorkType(mContext)<4){
                showToast(getString(R.string.no_wifi));
            }else{
                startToConfigCamera(ADD_LOCAL_IPC);
            }
        });
    }

    private void startToConfigCamera(int type){
        Intent intent = new Intent(mContext, ConfigCameraActivity.class);
        intent.putExtra("addType", type);
        startActivity(intent);
    }
}
